package com.itheima.entity;

import com.itheima.dto.GroupDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.logging.log4j.util.Strings;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Group {
    private Integer id;
    private String groupValue;
    private String tabValue;
    private String attrKey;
    private String attrName;
    private String attrValue;
    private Integer delFlag;
    private Integer type;
    private String configValue;
    private String validator;
    private String placeholder;
    private Integer canDelete;
    private Integer sortNum;

    public GroupDTO getGroupDTO() {
        GroupDTO g = new GroupDTO();
        g.setId(id);
        g.setGroup_value(groupValue);
        g.setTab_value(tabValue);
        g.setAttr_key(attrKey);
        g.setAttr_name(attrName);
        g.setAttr_value(attrValue);
        g.setDel_flag(delFlag);
        g.setType(type);
        if (Strings.isNotEmpty(configValue)) {
            List<ConfigValue> list = new ArrayList<>();
            for (String s : (configValue.split("&"))) {
                String[] split = s.split("=");
                ConfigValue configValue1 = new ConfigValue();
                configValue1.setLabel(split[0]);
                configValue1.setValue(split[1]);
                list.add(configValue1);
            }
            g.setConfig_value(list);
        }
        g.setValidator(validator);
        g.setPlaceholder(placeholder);
        g.setCan_delete(canDelete);
        g.setSort_num(sortNum);
        return g;
    }
}

